﻿using System.IO;
using YooAsset;

namespace Client.Base
{
    public class YAFileStreamEncryption : IEncryptionServices
    {
        public EncryptResult Encrypt(EncryptFileInfo fileInfo)
        {
            // mp4 mp3 不加密
            if (fileInfo.BundleName.Contains(".mp4") || fileInfo.BundleName.Contains(".mp3"))
            {
                EncryptResult result = new EncryptResult();
                result.Encrypted = false;
                return result;
            }
            else
            {
                var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
                for (int i = 0; i < fileData.Length; i++)
                {
                    fileData[i] ^= BundleStream.KEY;
                }

                EncryptResult result = new EncryptResult();
                result.Encrypted = true;
                result.EncryptedData = fileData;
                return result;
            }
        }
    }

}
